package Servlet;

import Pojo.User;
import Service.Serviceimpl.Manageserviceimpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;

public class ManageupdaterootServlet extends HttpServlet {
//   修改用户账号密码信息表
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        int id = Integer.parseInt(req.getParameter("id"));
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String aSwitch = req.getParameter("switch");

        int state;
        if (Objects.equals(aSwitch, "on")){
            state=1;
        }else {
            state=0;
        }
        User user = new User(id, username, password, state);
        boolean b = new Manageserviceimpl().updateUserManage(user);
        if (b){
            resp.getWriter().write("ok");
        }

    }
//删除用户账号密码信息表
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));
        System.out.println(id);
        boolean b = new Manageserviceimpl().delUserManage(id);
    }
}
